/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pe.edu.ucv.convertidores.gestionrequisitos;


import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

import pe.edu.ucv.daos.FindentityDAO;

import pe.edu.ucv.entidades.Hardware;


/**
 *
 * @author Administrator
 */
@FacesConverter(forClass=Hardware.class,value="hardwareconverter")
public class HardwareConverter implements Converter{
    
    @Override
    public String getAsString(FacesContext context, UIComponent component, Object valueToRender) {
        // Convert MyObj to its unique String representation.
         Hardware hardware = (Hardware) valueToRender;
        Integer id = hardware.getId();
        return String.valueOf(id);
    }

    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String submittedValue) {
        // Convert String to MyObj.
        FindentityDAO findDAO=new FindentityDAO();
        Integer id = Integer.parseInt(submittedValue);
        //System.out.println(id);
        Hardware ca = findDAO.findHardware(id);
        return ca;
    }
}
